import 'package:flutter/material.dart';
import 'package:hrcapp/utils/theme_colors.dart';

class HRCNFTOnchainDetailScreen extends StatelessWidget {
  const HRCNFTOnchainDetailScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ThemeColors.background,
      appBar: AppBar(
        backgroundColor: ThemeColors.cardBg,
        elevation: 0,
        centerTitle: true,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios, size: 16, color: Colors.black),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        title: const Text(
          '链上详情',
          style: TextStyle(
            fontSize: 20,
            fontWeight: FontWeight.bold,
            color: Colors.black,
          ),
        ),
      ),
      body: SafeArea(
        child: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children:
              [
                // NFT图片区域
                _buildNFTImageArea(),
                const SizedBox(height: 20),

                // 链上信息卡片
                _buildOnchainInfoCard(),
                const SizedBox(height: 30),

                // 操作按钮
                _buildActionButton(context),
                const SizedBox(height: 60),
              ],
            ),
          ),
        ),
      ),
    );
  }

  // 构建NFT图片区域
  Widget _buildNFTImageArea() {
    return Container(
      width: double.infinity,
      height: 180,
      decoration: BoxDecoration(
        color: const Color(0xFFFFFAF0),
        borderRadius: BorderRadius.circular(16),
      ),
      child: Center(
        child: Text(
          '苏绣《牡丹图》',
          style: TextStyle(
            fontSize: 24,
            color: const Color(0xFFD2B48C),
          ),
        ),
      ),
    );
  }

  // 构建链上信息卡片
  Widget _buildOnchainInfoCard() {
    return Container(
      width: double.infinity,
      decoration: BoxDecoration(
        color: ThemeColors.cardBg,
        borderRadius: BorderRadius.circular(16),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.1),
            spreadRadius: 0,
            blurRadius: 20,
            offset: const Offset(0, 4),
          ),
        ],
      ),
      child: Padding(
        padding: const EdgeInsets.all(20),
        child:
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 基本信息
            const Text(
              'NFT基本信息',
              style: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.bold,
                color: Colors.black,
              ),
            ),
            const SizedBox(height: 30),

            // NFT名称
            _buildInfoItem('NFT名称', '苏绣《牡丹图》'),
            const SizedBox(height: 20),

            // NFT编号
            _buildInfoItem('NFT编号', 'HRC-NFT-2023-001'),
            const SizedBox(height: 20),

            // 创作者
            _buildInfoItem('创作者', '张明'),
            const SizedBox(height: 20),

            // 创建时间
            _buildInfoItem('创建时间', '2023-09-15 14:30:25'),
            const SizedBox(height: 30),

            // 区块链信息
            const Text(
              '区块链信息',
              style: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.bold,
                color: Colors.black,
              ),
            ),
            const SizedBox(height: 30),

            // 合约地址
            _buildInfoItem('合约地址', '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D', true, true),
            const SizedBox(height: 20),

            // 当前所有者
            _buildInfoItem('当前所有者', '0x1234567890123456789012345678901234567890', true, true),
            const SizedBox(height: 20),

            // 交易次数
            _buildInfoItem('交易次数', '1'),
          ],
        ),
      ),
    );
  }

  // 构建信息项
  Widget _buildInfoItem(String label, String value, [bool isLink = false, bool isSmall = false]) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children:
      [
        Text(
          label,
          style: TextStyle(
            fontSize: 14,
            color: ThemeColors.textSecondary,
          ),
        ),
        const SizedBox(width: 10),
        Expanded(
          child:
          Text(
            value,
            style: TextStyle(
              fontSize: isSmall ? 12 : 14,
              fontWeight: FontWeight.bold,
              color: isLink ? ThemeColors.primary : Colors.black,
            ),
            overflow: TextOverflow.ellipsis,
            maxLines: 1,
          ),
        ),
      ],
    );
  }

  // 构建操作按钮
  Widget _buildActionButton(BuildContext context) {
    return Container(
      width: double.infinity,
      height: 50,
      decoration: BoxDecoration(
        color: ThemeColors.primary,
        borderRadius: BorderRadius.circular(25),
        boxShadow: [
          BoxShadow(
            color: ThemeColors.primary.withOpacity(0.3),
            spreadRadius: 2,
            blurRadius: 5,
            offset: const Offset(0, 3),
          ),
        ],
      ),
      child: TextButton(
        onPressed: () {
          // 查看完整链上记录按钮点击事件
          ScaffoldMessenger.of(context).showSnackBar(
            const SnackBar(content: Text('查看完整链上记录功能待实现')),
          );
        },
        child:
        const Text(
          '查看完整链上记录',
          style: TextStyle(
            fontSize: 18,
            fontWeight: FontWeight.bold,
            color: Colors.white,
          ),
        ),
      ),
    );
  }
}